import {ObjectType} from '../type';


/**
 * JS基础类型
 */
const baseTypes: Function[] = [
  String,
  Number,
  Boolean,
  Symbol,
  Object,
  Buffer,
  Function,
];

/**
 * 函数工具类
 * @author Zhang
 * @date 2019-3-16 20:20:42
 */
export class FunctionUtils {

  /**
   * 将arguments对象转为数组
   * @param argumentsObj
   */
  static arguments2array(argumentsObj: IArguments): any[] {
    const args = [];
    for (let _i = 0; _i < argumentsObj.length; _i++) {
      args[_i] = argumentsObj[_i];
    }
    return args;
  }

  /**
   * 判断给定类型是不是JavaScript基础类型
   * @param type
   */
  static isBaseType(type: ObjectType<any>): boolean {
    return baseTypes.includes(type);
  }
}
